from django.db import models


class Book(models.Model):
    title = models.CharField(verbose_name='书名', max_length=32)
    price = models.DecimalField(verbose_name='价格', max_digits=8, decimal_places=2)  # 最大八位，两个浮点小数
    date = models.DateField(verbose_name='出版时间', )
    publish = models.ForeignKey(to='Publish', on_delete=models.CASCADE)
    authors = models.ManyToManyField(verbose_name='作者', to='Author')

    def __str__(self):
        return self.title

    class Meta:  # 表名、后台admin显示名
        verbose_name = '书籍表'
        verbose_name_plural = verbose_name


class Publish(models.Model):
    title = models.CharField(verbose_name='出版社', max_length=32)

    def __str__(self):
        return self.title

    class Meta:  # 表名、后台admin显示名
        verbose_name = '出版社表'
        verbose_name_plural = verbose_name


class Author(models.Model):
    name = models.CharField(verbose_name='作者', max_length=32)

    def __str__(self):
        return self.name

    class Meta:  # 表名、后台admin显示名
        verbose_name = '作者表'
        verbose_name_plural = verbose_name
